package com.whitewolf.gamer.controller;

import com.whitewolf.gamer.common.annotation.CurrentUser;
import com.whitewolf.gamer.common.model.Result;
import com.whitewolf.gamer.security.UserDetailsImpl;
import com.whitewolf.gamer.service.UserService;
import com.whitewolf.gamer.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/api/v1/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 获取用户个人资料
     */
    @GetMapping("/profile")
    public Result<UserVO> getUserProfile(@CurrentUser UserDetailsImpl userDetails) {
        UserVO userVO = userService.getUserProfile(userDetails.getUser().getId());
        return Result.success(userVO);
    }

    /**
     * 更新用户个人资料
     */
    @PutMapping("/profile")
    public Result<Void> updateUserProfile(@CurrentUser UserDetailsImpl userDetails,
                                          @RequestBody @Valid UserProfileDTO userProfileDTO) {
        boolean success = userService.updateUserProfile(userDetails.getUser().getId(), userProfileDTO);
        return success ? Result.success() : Result.failure();
    }

    /**
     * 获取用户余额
     */
    @GetMapping("/balance")
    public Result<BigDecimal> getUserBalance(@CurrentUser UserDetailsImpl userDetails) {
        BigDecimal balance = userService.getUserBalance(userDetails.getUser().getId());
        return Result.success(balance);
    }

    /**
     * 获取用户收藏列表
     */
    @GetMapping("/favorites")
    public Result<Void> getFavorites(@CurrentUser UserDetailsImpl userDetails) {
        // TODO: 实现收藏功能
        return Result.success();
    }

    /**
     * 添加收藏
     */
    @PostMapping("/favorites")
    public Result<Void> addFavorite(@CurrentUser UserDetailsImpl userDetails,
                                    @RequestParam Long itemId,
                                    @RequestParam String itemType) {
        // TODO: 实现收藏功能
        return Result.success();
    }

    /**
     * 取消收藏
     */
    @DeleteMapping("/favorites/{favoriteId}")
    public Result<Void> removeFavorite(@CurrentUser UserDetailsImpl userDetails,
                                       @PathVariable Long favoriteId) {
        // TODO: 实现收藏功能
        return Result.success();
    }
}